<template>
  <section class="page">
    <headerbar>问题</headerbar>

    <section class="inner-content">

      <div class="text-block" @click="showType()">
        <div class="name color-default input-name"><i class="required color-red">*</i>辅导层级：</div>
        <div class="value"><input readonly v-model="data.coachinglevelLabel" type="text" placeholder="请选择辅导层级"></div>
      </div>
      <div v-if="data.coachinglevel === '1'" class="text-block" @click="showCityDept()">
        <div class="name color-default input-name"><i class="required color-red">*</i>市级部门：</div>
        <div class="value"><input readonly v-model="data.cityDeptLabel" type="text" placeholder="请选择部门"></div>
      </div>
      <div v-if="data.coachinglevel === '2'" class="text-block" @click="showArea()">
        <div class="name color-default input-name"><i class="required color-red">*</i>区县列表：</div>
        <div class="value"><input readonly v-model="data.areaListLabel" type="text" placeholder="请选择区县"></div>
      </div>
      <div v-if="data.coachinglevel === '2'" class="text-block" @click="showAreaDept()">
        <div class="name color-default input-name"><i class="required color-red">*</i>区县部门：</div>
        <div class="value"><input readonly v-model="data.areaDeptLabel" type="text" placeholder="请选择区县部门"></div>
      </div>
      <div class="text-block" @click="showTearcher()">
        <div class="name color-default input-name"><i class="required color-red">*</i>辅导师：</div>
        <div class="value"><input readonly v-model="data.tearcherLabel" type="text" placeholder="请选择辅导师"></div>
      </div>
      <div class="input-row-wrap">
        <div class="name">问题：</div>
        <textarea v-model="data.contents" placeholder="请您在此处填写问题内容" name="" id="" cols="30" rows="5"></textarea>
      </div>

      <div class="text-block" v-if="data.tearcherLabel !== ''">
        <div class="name color-default input-name"><i class="required color-red">*</i>联系电话：</div>
        <div class="value"><input readonly v-model="data.mobile" type="text" @click="callNumber()"></div>
        <span class="color-tip fa fa-phone-alt"></span>
      </div>

      <div class="mgt-10"></div>
      <div @click="submit()" class="default-block-btn">提交</div>
      <div class="mgt-10"></div>
    </section>
  </section>
</template>

<script>
  import tools from '@/utils/tools'
  import api from '@/common/config/api'
  import loginService from '@/service/loginService'
  import moment from 'moment'
  import fileIcon from '../../../../static/images/up_document.png'

  export default {
    name: 'organizationalLifeAdd',
    data () {
      return {
        fn: tools,
        data: {
          coachinglevel: '',
          coachinglevelLabel: '',
          cityDept: '',
          cityDeptLabel: '',
          areaList: '',
          areaListLabel: '',
          areaDept: '',
          areaDeptLabel: '',
          tearcher: '',
          tearcherLabel: '',
          contents: '',
          durationList: {},
          areaLists: [],
          areaDeptLists: [],
          cityAreas: [],
          areaDeptRuslt: [],
          tearcherLists: [],
          tearcherRuslt: [],
          parentId: '',
          rankLevel: '',
          userInfo: this.$store.state.userInfo,
          mobile: ''
        },

      }
    },
    created () {
      this.resumeData()
    },
    methods: {
      resumeData () {
        if (this.$store.state.tutoringVillageAdd) {
          this.data = this.$store.state.tutoringVillageAdd
          this.$store.state.tutoringVillageAdd = null
        }
      },
      submit () {
        if (this.data.coachinglevel === '') {
          return tools.tip('请选择辅导层级！')
        }
        if (this.data.coachinglevel === '1' && this.data.cityDept === '') {
          return tools.tip('请选择市级部门！')
        }
        if (this.data.coachinglevel === '2' && this.data.areaList === '') {
          return tools.tip('请选择区县！')
        }
        if (this.data.coachinglevel === '2' && this.data.areaDept === '') {
          return tools.tip('请选择区县部门！')
        }
        if (this.data.tearcher === '') {
          return tools.tip('请选择辅导师！')
        }
        if (this.data.contents === '') {
          return tools.tip('请填写问题内容！')
        }

        let deptId = ''
        let depetName = ''
        let coachLevle = ''
        if (this.data.coachinglevel === '1') {
          deptId = this.data.cityDept
          depetName = this.data.cityDeptLabel
          coachLevle = '0'
        } else {
          deptId = this.data.areaDept
          depetName = this.data.areaDeptLabel
          coachLevle = '1'
        }
        let data = {
          coachLevle: coachLevle,
          deptId: deptId,
          depetName: depetName,
          areaCode: this.data.areaList,
          areaName: this.data.areaListLabel,
          coachTeacherId: this.data.tearcher,
          coachTeacherName: this.data.tearcherLabel,
          questionContext: this.data.contents,
          questionerId: this.data.userInfo.id,
          questionerName: this.data.userInfo.nickname
        }
        loginService.coachSuggest(data).then((res) => {
          if (res.code !== 0) {
            return tools.tip(res.message)
          } else {
            tools.tip('保存成功')
            tools.back()
          }
        })
      },
      // 选择辅导层级
      showType () {
        this.$createActionSheet({
          title: '辅导层级',
          active: 10,
          data: [
            {
              scope: '1',
              content: '市级'
            },
            {
              scope: '2',
              content: '区级'
            }
          ],
          onSelect: (item, index) => {
            this.data.coachinglevelLabel = item.content
            this.data.coachinglevel = item.scope
            this.$forceUpdate()
          },
          onCancel: () => {
          }
        }).show()
      },
      // 选择市级部门
      showCityDept () {
        this.$store.state.tutoringVillageAdd = this.data
        this.$router.push({name: 'groupSelect'})
      },
      // 选择区县列表
      showArea () {
        this.$store.state.tutoringVillageAdd = this.data
        this.$router.push({name: 'areaSelect'})
      },
      // 选择区县部门
      showAreaDept () {
        this.$store.state.tutoringVillageAdd = this.data
        this.$router.push({path: `/areaGroupSelect/${this.data.areaList}`})
      },
      // 选择辅导师
      showTearcher () {
        if (this.data.cityDept === '' && this.data.areaDept === '') {
          return tools.tip('请先选择部门')
        }
        let groupId = ''
        if (this.data.coachinglevel === '1') {
          groupId = this.data.cityDept
        } else {
          groupId = this.data.areaDept
        }
        this.$store.state.tutoringVillageAdd = this.data
        this.$router.push({path: `/tearcherSelect/${groupId}`})
      },
      callNumber () {
        if (this.data.mobile === '') {
          return
        }
        if (window.android && window.android.callNumber) {
          window.android.callNumber(this.data.mobile)
        }
      }
    }
  }
</script>

<style scoped>

</style>
